package com.ruoyi.project.dj.controller;

import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.dj.domain.DjStandardStandard;
import com.ruoyi.project.dj.service.IDjStandardStandardService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 支部标准化 - 标准化制度
 */
@RestController
@RequestMapping("/dj/standard")
public class DjStandardStandardController extends BaseController {
    @Autowired
    private IDjStandardStandardService djStandardStandardService;

    /**
     * 查询标准化制度列表
     */
    @RequiresPermissions("dj:standard:list")
    @GetMapping("/list")
    public TableDataInfo list(DjStandardStandard djStandardStandard) {
        startPage();
        List<DjStandardStandard> list = djStandardStandardService.selectDjStandardStandardList(djStandardStandard);
        return getDataTable(list);
    }

    /**
     * 查询标准化制度详细信息
     */
    @RequiresPermissions("dj:standard:query")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Integer id) {
        DjStandardStandard djStandardStandard = djStandardStandardService.selectDjStandardStandardById(id);
        return AjaxResult.success(djStandardStandard);
    }

    /**
     * 新增标准化制度
     */
    @RequiresPermissions("dj:standard:add")
    @Log(title = "标准化制度", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody DjStandardStandard djStandardStandard) {
        return toAjax(djStandardStandardService.insertDjStandardStandard(djStandardStandard));
    }

    /**
     * 修改标准化制度
     */
    @RequiresPermissions("dj:standard:edit")
    @Log(title = "标准化制度", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody DjStandardStandard djStandardStandard) {
        return toAjax(djStandardStandardService.updateDjStandardStandard(djStandardStandard));
    }

    /**
     * 删除标准化制度
     */
    @RequiresPermissions("dj:standard:remove")
    @Log(title = "标准化制度", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Integer id) {
        return toAjax(djStandardStandardService.deleteDjStandardStandardById(id));
    }
    
    /**
     * 批量删除标准化制度
     */
    @RequiresPermissions("dj:standard:remove")
    @Log(title = "标准化制度", businessType = BusinessType.DELETE)
    @DeleteMapping("/batchRemove")
    public AjaxResult batchRemove(@RequestBody Integer[] ids) {
        int rows = 0;
        for (Integer id : ids) {
            rows += djStandardStandardService.deleteDjStandardStandardById(id);
        }
        return toAjax(rows);
    }
}